package com.sanjiahantang.ythshopping.presenter;

import android.content.Context;

import com.sanjiahantang.ythshopping.config.ConfigValue;
import com.sanjiahantang.ythshopping.http.BaseDelegate;
import com.sanjiahantang.ythshopping.http.ExceptionHelper;
import com.sanjiahantang.ythshopping.http.OkHttpClientManager;
import com.sanjiahantang.ythshopping.model.GoodsBuyModel;
import com.sanjiahantang.ythshopping.utils.Utils;
import com.sanjiahantang.ythshopping.views.GoodsBuyView;
import com.squareup.okhttp.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by admin on 2017/6/20.
 */

public class GoodsBuyPresenter {

    GoodsBuyView goodsbuyview;
    Context context;
    String goods_id;
    String num;
    String attribute;


    public GoodsBuyPresenter(GoodsBuyView goodsbuyview,Context context,String goods_id,String num,String attribute)
    {
        this.context=context;
        this.goodsbuyview=goodsbuyview;
        this.goods_id=goods_id;
        this.num=num;
        this.attribute=attribute;

    }

    public void loadGoodscar()
    {
        Map<String ,String> params=new HashMap<>();
        params.put("key", ConfigValue.DATA_KEY);
        params.put("goods_id",goods_id);
        params.put("num",num);
        if (!attribute.equals(""))
        {
            params.put("attribute",attribute);
        }


        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "goods/buy", params, new BaseDelegate.ResultCallback<GoodsBuyModel>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                Utils.showToast(context, ExceptionHelper.getMessage(e, context));
            }

            @Override
            public void onResponse(GoodsBuyModel response, Object tag) {

                goodsbuyview.getGoodsCar(response);
            }
        });
    }

}
